<?php
class LopsController extends AppController {

	var $name = 'Lops';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->Lop->recursive = 0;
		$this->set('lops', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Lop', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('lop', $this->Lop->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Lop->create();
			if ($this->Lop->save($this->data)) {
				$this->Session->setFlash(__('The Lop has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Lop could not be saved. Please, try again.', true));
			}
		}
		$daotaohes = $this->Lop->Daotaohe->find('list');
		$khoas = $this->Lop->Khoa->find('list');
		$nganhs = $this->Lop->Nganh->find('list');
		$this->set(compact('daotaohes', 'khoas', 'nganhs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Lop', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Lop->save($this->data)) {
				$this->Session->setFlash(__('The Lop has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The Lop could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Lop->read(null, $id);
		}
		$daotaohes = $this->Lop->Daotaohe->find('list');
		$khoas = $this->Lop->Khoa->find('list');
		$nganhs = $this->Lop->Nganh->find('list');
		$this->set(compact('daotaohes','khoas','nganhs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Lop', true));
			$this->redirect(array('action' => 'index'));
		}
		if ($this->Lop->del($id)) {
			$this->Session->setFlash(__('Lop deleted', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('The Lop could not be deleted. Please, try again.', true));
		$this->redirect(array('action' => 'index'));
	}

}
?>